const dirList = [
    {id:100, dirName: '目录1', orderNo:8},
    {id:200, dirName: '目录2', orderNo:9, parentId: 100},
    {id:300, dirName: '目录3', orderNo:5},
]

const fileList = [
    {id:10, fileName:'文件1.jpg', dirId:100, orderNo:2},
    {id:20, fileName:'文件2.jpg', dirId:100, orderNo:4},
]

const toFileTree = (topDir,dirList,fileList) => {
    topDir.forEach(item => {
        const sonDirNode = dirList.filter(dir => dir.parentId === item.id);
        const sonFileNode = fileList.filter(file => file.dirId === item.id);
        const sonNodeList = [...sonDirNode,...sonFileNode];
        item['sonNodeList'] = sonNodeList;
        if(sonDirNode.length>0){
            toFileTree(sonDirNode,dirList,fileList)
        }
    })
    return topDir;
}

const topDir = dirList.filter(dir => !dir?.parentId);
console.log(toFileTree(topDir,dirList,fileList));